package com.example.demo.redisson.ratelimiter.controller;

import com.example.demo.redisson.ratelimiter.annotation.RedisRateLimit;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author weigang
 * @create 2022-12-16 16:09
 */
@RestController
public class redisRatelimitController {
    /**
     * 设置limitKey=redisRatelimit,并且每5秒许可证只有1个
     */
    @RedisRateLimit(limitKey = "redisRatelimit",value =1,time = 5)
    @GetMapping("/redisRatelimit")
    public String redisRatelimit() throws Exception{
        //假设业务处理了1秒
        TimeUnit.SECONDS.sleep(5);
        return "success";
    }

}
